#!/usr/bin/env python
# encoding: utf-8


"""
@file: trig_ineq.py
@time: 2017/3/8 下午9:12
"""

from mathsolver.functions.base import *
from sympy import pi, acos


def solve_cos_ineq(ineq):
    """
    :param ineq:
    :return:
    """
    l, op, r = ineq.sympify()
    k_symbol = sympify('k')
    # cos(x) < a
    if op.find('<') >= 0:
        if r > 1:
            return S.Reals
        elif r < -1:
            return EmptySet()
        elif -1 < r <= 1:
            return Interval.open(2 * k_symbol * pi + acos(r), 2 * k_symbol * pi + 2 * pi - acos(r))
        elif r >= 1:
            return S.Reals
        elif r <= -1:
            return EmptySet()
        elif -1 <= r < 1:
            return Interval(2 * k_symbol * pi + acos(r), 2 * k_symbol * pi + 2 * pi - acos(r))
        else:
            raise Exception('invalidate value')
    else:
        if r < -1:
            return S.Reals
        elif r > 1:
            return EmptySet()
        elif -1 <= r < 1:
            return Interval.open(2 * k_symbol * pi - acos(r), 2 * k_symbol * pi + acos(r))
        elif r <= -1:
            return S.Reals
        elif r >= 1:
            return EmptySet()
        elif -1 < r <= 1:
            return Interval(2 * k_symbol * pi - acos(r), 2 * k_symbol * pi + acos(r))
